<?php
include_once $_SERVER['DOCUMENT_ROOT'].'/phorm/model/fields/Text.php';

class SerializedPHPObject extends TextArea
{

	public function __construct(IDatabaseRecord &$object, $defaultValue = null)
	{
		// previoulsy was using debug_backtrace()
		// but we found an issue when (we think) php was running as CGI.  The ['object']
		// key was not being passed.
		// signature was:
		// public function __construct($length = null, $defaultValue = null)
		// $this->model was being set via:
		// $tmp =  debug_backtrace();
		// $this->model        = &$tmp[1]['object'];
		
		$this->model               = $object;
		$this->field_type          = "textarea";
		$this->defaultValue        = $defaultValue;
	}

	public function __get($property)
	{
		$retVal = null;
		if($property == 'value'):
			$retVal = $this->data['value'];
		elseif($property == 'userDefinedValue'):
			$retVal = unserialize($this->data['value']);
		endif;
		
		return $retVal;
	}
	
	public function handleUserDefinedValue(&$value)
	{
		$value = serialize($value);
	}
}
?>
